import http from '../http/index'

interface CfgType {
  url: string
  method: Method
  data?: Object
  params?: Object
}

class Modal {
  request<T>(raw: ReqBase, data?: any) {
    const res: ApiResult<T> = { code: -1, error: '' }
    let url = raw.url.toString()
    if (raw.activePath) {
      const _path = raw.activePath.toString()
      const path = '/' + data[_path]
      url = url + path
      Reflect.deleteProperty(data, _path)
    }
    const cfg: CfgType = {
      url,
      method: raw.method
    }
    if (cfg.method === 'get') cfg.params = data
    else if (cfg.method === 'post') cfg.data = data
    http.request(cfg)
  }
}

export default Modal
